package com.coke.spring.security.filter;

import cn.hutool.core.util.StrUtil;
import com.coke.spring.security.token.IpAuthenticationToken;
import com.coke.spring.security.token.MobelAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author cwm
 * @Description 配置手机登录过滤器
 * @date 2021/8/26 下午1:25
 * @Version 1.0
 */
public class MObelAuthenticationProcessingFilter extends AbstractAuthenticationProcessingFilter {
    private static final AntPathRequestMatcher DEFAULT_ANT_PATH_REQUEST_MATCHER = new AntPathRequestMatcher("/loginMobel",
            "POST");

    public MObelAuthenticationProcessingFilter() {
        super(DEFAULT_ANT_PATH_REQUEST_MATCHER);
    }
    @Override
    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
        String phone = request.getParameter("phone");
        String code = request.getParameter("code");
        return getAuthenticationManager().authenticate(new MobelAuthenticationToken(phone, code));

    }
}
